<template>
  <div class="head" v-loading="loading">
    <div class="title">
      <span>{{ baseInfo.communityName }}</span>
      <div>
        <el-button type="primary" icon="Edit" @click="editMode">编辑</el-button>
      </div>
    </div>
    <el-row :gutter="20" style="margin: 0">
      <el-col :span="item.span" style="padding: 0" v-for="item in column" :key="item">
        <div class="col-content">
          <div class="label-info"
            ><el-icon class="icons"><component :is="item.icon" /></el-icon>{{ item.label }}</div
          >
          <div class="content-info">
            <div v-if="item.itemIf">
              <el-tag effect="dark" :type="baseInfo[item.key] ? 'success' : 'danger'">
                {{ baseInfo[item.key] ? '启用' : '禁用' }}
              </el-tag>
            </div>
            <div v-else>
              {{ baseInfo[item.key] }}
            </div>
          </div>
        </div>
      </el-col>
    </el-row>
    <CommunityUpdataDrawer ref="communityUpdataRef" @getData="getData"></CommunityUpdataDrawer>
  </div>
</template>

<script lang="ts" setup>
  import { ref, onMounted } from 'vue'
  import { getCommunityById } from '@/api/controller/community-controller/index'
  import CommunityUpdataDrawer from '../../../communityTable/components/communityUpdataDrawer.vue'
  const loading = ref(true)
  const communityId = ref(history.state?.id)

  const column = [
    { key: 'city', label: '所在市:', span: 8, icon: 'OfficeBuilding' },
    { key: 'area', label: '所在区:', span: 8, icon: 'OfficeBuilding' },
    { key: 'position', label: '定位:', span: 8, icon: 'MapLocation' },
    { key: 'communityAddress', label: '地址:', span: 16, icon: 'Location' },
    { key: 'status', label: '状态:', span: 8, icon: 'PriceTag', itemIf: true },
    { key: 'remark', label: '备注:', span: 24, icon: 'Message' },
  ]
  //获取数据
  const baseInfo = ref<any>({})
  onMounted(async () => {
    getData()
  })

  const getData = async () => {
    try {
      loading.value = true
      let res = await getCommunityById({ id: communityId.value })
      baseInfo.value = res.data
    } finally {
      loading.value = false
    }
  }

  //编辑
  const communityUpdataRef = ref()
  const editMode = () => {
    communityUpdataRef.value.show(baseInfo.value)
  }
</script>

<style lang="scss" scoped>
  .title {
    display: flex;
    justify-content: space-between;
    margin-bottom: 10px;
    span {
      font-size: 20px;
      font-weight: 600;
    }
  }
  .head {
    background-color: white;
    margin: 0 0 16px 0;
    padding: 20px;
    border-radius: 6px;
    box-shadow: 0px 0px 6px rgba(0, 0, 0, 0.12);
  }
  .col-content {
    display: flex;
    height: 100%;
    .label-info {
      display: flex;
      align-items: center;
      justify-content: end;
      color: #606266;
      font-weight: bold;
      font-size: 14px;
      background-color: #f5f7fa;
      min-width: 80px;
      border: 1px solid #ebeef5;
      padding: 10px;
      .icons {
        margin-right: 6px;
        height: 16px;
        width: 16px;
      }
    }
    .content-info {
      display: flex;
      align-items: center;
      width: 100%;
      padding: 10px;
      border: 1px solid #ebeef5;
    }
  }
</style>
